<?php
namespace PsiFramework\Classes\Util\Object\Treeview;

import('Classes.Util.Object.Treeview.TreeviewNode');
import('Classes.Util.Object.Collection');
import('Classes.Util.Object.Json');

use \PsiFramework\Classes\Util\Object\Treeview\TreeviewNode;
use \PsiFramework\Classes\Util\Object\Collection;
use \PsiFramework\Classes\Util\Object\Json;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The TreeviewNodeCollection class is used to TreeviewNode Collections
 *
 * @package Util.Object
 */
class TreeviewNodeCollection extends Collection
{

    public function __construct(/*TreeviewNode[]*/ $nodes=array())
    {
        parent::__construct($nodes);
    }

    public function getNodes()
    {
        return $this->getElements();
    }

    public function setNodes(/*TreeviewNode[]*/ $nodes)
    {
        $this->setElements($nodes);
    }

    public function addNode(TreeviewNode $node)
    {
        $this->addElement($node);
    }

    public function unserialize($value)
    {
        $jsonObject = new Json();
        $jsonObject->unserialize($value);

        foreach ($jsonObject->getObject() as $element) {
            $node = new TreeviewNode();
            $node->unserialize($element);
            $this->addElement($node);
        }
    }

}
